﻿@using OPM
@using OPM.MultiResource;
@model OPM.Models.GetCase
@{
    
    var sl = new SL();
    SelectList severities = sl.GetSeverity();
    SelectList listPriorities = sl.GetPriority();
    SelectList secrets = sl.GetSecret(); 
}
<div id="servicePage4" class="servicePage dNone">
    <table>
        <tr>
            <td>@Multi.Objective_text</td>
            <td>
                <a href="@Url.Action("LovCaseObjective", "Complaint")?a=obj" data-block="obj" class="formBtn2 dBlock">@Multi.objectivity</a><span class="star">*</span>
                <span id="block_obj"></span>
            </td>
            <td rowspan="4">@Multi.SummarySubject</td>
            <td rowspan="4" class="tdBottom">
                <textarea name="topic" id="summary"></textarea>
            </td>
        </tr>
        <tr>
            <td>@Multi.CaseType</td>
            <td>
                 <a href="@Url.Action("LovCaseType", "Complaint")?a=case_type" data-block="case_type" class="formBtn3 dBlock">@Multi.CaseType
                 </a>
                 <span id="block_case_type"></span>
                @*<a href="@Url.Action("LovCaseType", "Complaint")?a=case_type" data-block="case_type" class="formBtn2 dBlock">@Multi.CaseType</a> <span class="star">*</span>*@
               
                @*<script>
                    function changedFromLovCaseType(case_type_id) {
                        $('#block_organizatoin').html();
                        $('#a_add_org_related').attr('href', '@Url.Action("LovCaseTypeOrgOwneUnderCaseType")?case_type_id=' + case_type_id);
                    }
                </script>*@
            </td>
        </tr>
       @* <tr>
            <td>@Multi.CaseTerminalType</td>
            <td>
                <a href="@Url.Action("LovCaseTerminalType", "Complaint")?a=terminal_type_id" data-block="terminal_type_id" class="formBtn dBlock">@Multi.CaseTerminalType</a>
                <span id="block_terminal_type_id"></span>
            </td>
        </tr>*@
        <tr>
            <td>@Multi.CaseTypeOrgOwne</td>
            <td>
                <a href="@Url.Action("LovOrganization2", "Complaint")?a=organizatoin" data-block="organizatoin" class="formBtn3 dBlock">เพิ่มหน่วยงานที่เกี่ยวข้อง
                </a>
                <span id="block_organizatoin"></span>
            </td>
        </tr>
        <tr>
            <td>@Multi.used_inform_with</td>
            <td>
                <input type="text" name="timedate-input" class="full-text" id="used_inform_with" />
            </td>
            <td rowspan="7">@Multi.detail</td>
            <td rowspan="7" class="tdBottom">
                <textarea name="detail" id="detail"  style="height: 324px;"></textarea>
                <span class="star">*</span>
            </td>
        </tr>
        <tr>
            <td>@Multi.defendent</td>
            <td>
                <input type="text" name="timedate-input" class="full-text" id="defendent" />
            </td>
        </tr>
        <tr>
            <td>@Multi.date_occurrenced_from_</td>
            <td>
                <input type="text" name="date_opened" id="date_occurrenced_from" class="date-input"
                       value="@(Model.date_occurrenced_from.HasValue ?
                       Model.date_occurrenced_from.Value.ToString("dd/MM/yyyy", new System.Globalization.CultureInfo("en-US")) : "")" />
                @*<input type="text" name="startdate-input" class="date-input" id="date_occurrenced_from" value="" />*@
            </td>
        </tr>
        <tr>
            <td>@Multi.date_occurrenced_to_</td>
            <td>
                <input type="text" name="date_opened" id="date_occurrenced_to" class="date-input"
                       value="@(Model.date_occurrenced_to.HasValue ?
                       Model.date_occurrenced_to.Value.ToString("dd/MM/yyyy", new System.Globalization.CultureInfo("en-US")) : "")" />
            @*<input type="text" name="enddate-input" class="date-input" id="date_occurrenced_to" value="" /></td>*@
        </tr>
        <tr>
            <td>@Multi.time_occurrenced</td>
            <td>
                <input type="text" name="timedate-input" class="full-text" id="time_occurrenced" value="" /></td>

            
        </tr>
        <tr>
            <td>@Multi.case_area</td>
            <td>
                <input type="text" name="timedate-input" class="full-text location_input" id="case_area" value="" />
                <p>@Multi.area</p>
                <a id="district_achor" href="@Url.Action("GetCrime", "Complaint")?a=crime&country_id=@(Model.country_id)&province_id=@(Model.province_id)&district_id=@(Model.district_id)&subdistrict_id=@(Model.subdistrict_id)"
                   data-block="block_crime" class="formBtn dBlock">@Multi.local_scene</a>
                <p style="color: gray" id="locationToRedirect">@Model.province_text @Model.district_text @Model.subdistrict_text</p>
                <input type="hidden" name="country_id" id="country_id" value="@Model.country_id" />
                <input type="hidden" name="province_id" id="province_id" value="@Model.province_id" />
                <input type="hidden" name="district_id" id="district_id" value="@Model.district_id" />
                <input type="hidden" name="subdistrict_id" id="subdistrict_id" value="@Model.subdistrict_id" />
            </td>
        </tr>
        <tr>
            <td>@Multi.postcode</td>
            <td>
                <input type="text" name="timedate-input" class="full-text" id="postcode" value="" />
            </td>
            
        </tr>
        <tr>
            <td>@Multi.map</td>
            <td>
                <div id="map_canvas" style="width: 250px; height: 300px;"></div>
                <input id="lat_value" name="lat_value" type="hidden" />
                <input id="lon_value" name="lon_value" type="hidden" />
            </td>
            <td  rowspan="3" style="vertical-align: top">@Multi.reference</td>
            <td  rowspan="3" class="tdBottom">
                <textarea name="org-input" id="reference" style="height:390px;"></textarea>
            </td>
        </tr>
        <tr>
            <td>@Multi.is_secret</td>
            <td>
                <select name="secret-level" id="is_secret">
                    <option value="F" selected>เปิดเผย</option>
                    <option value="T">ปกปิด</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>@Multi.is_in_court</td>
            <td>
                <select name="sue-staus" id="is_in_court">
                    <option value="F">ไม่อยู่ในการพิจารณาคดี</option>
                    <option value="T">อยู่ในการพิจารณาคดี</option>
                </select>
                <span class="star">*</span>
            </td>
            
        </tr>
        <tr>
            <td>@Multi.file_input</td>
            <td>
                <input type="file" id="case_attachment_input" />
                <span id="block_case_attachments">
                    @foreach (var ca in (Model == null || Model.list_case_attachment == null ? new List<CaseAttachment>() :
                        Model.list_case_attachment))
                    {
@*
                ด้านล่างคือ sourcecode เวลาเลือกไฟล์ใหม่ แล้ว add เข้ามาผ่าน javascript
                <input type="hidden" name="file_content" value=" =" />
                <input type="hidden" name="file_description" value="sadf"/>
                <input type="hidden" name="doc_type_id" value="1"/>
                <input type="hidden" name="doc_no" value="asdfasdf"/>
                <input type="hidden" name="doc_date" value="26/05/2558"/>
                <input type="hidden" name="doc_ref_no" value="sadf"/>
                <input type="hidden" name="doc_ref_date" value="26/05/2558"/>
                <input type="hidden" name="file_name" value="26/05/2558"/>
                <input type="hidden" name="doc_type" value="I"/>
                <div class="blockReAction" id="file_new_attach_1">
                    dell_copper_microserver.jpg<span onclick="removeBox1('file_new_attach_1');"></span>
                </div>
                        *@

                        
                        <div class="blockReAction">
                            @ca.file_name (@(ca.doc_type == "I" ? "รับเข้า" : (ca.doc_type == "O" ? "ส่งออก" : "อื่นๆ")))
                        </div> 
                    }
                </span>
            </td>
            <td>@Multi.status</td>
            <td>
                <a href="@Url.Action("LovCaseStatus", "Complaint")?a=status" data-block="status" class="formBtn2 dBlock">@Multi.operating_status</a><span class="star">*</span>
                <span id="block_status"></span>
            </td>
            
        </tr>
        <tr>
            <td>@Multi.severity_id</td>
            <td class="radio_form">
                @foreach (var sv in severities)
                {
                    <label>
                        <input type="radio" name="severity_id" class="severity_id" value="@sv.Value" @(Model.severity_id == sv.Value ? " checked=\"checked\"" : "") />
                        @sv.Text
                    </label>
                }
            </td>
            <td rowspan="2">@Multi.diagnosis_input</td>
            <td rowspan="2" class="tdBottom">
                <textarea name="diagnosis-input" class="half-textarea" id="diagnosis-input"></textarea>
                <span class="star">*</span>
            </td>
        </tr>
        <tr>
            <td>@Multi.priority_id</td>
            <td class="radio_form">
                @foreach (var sv in listPriorities)
                {
                    <label>
                        <input type="radio" name="priority_id" class="priority_id" value="@sv.Value" @(Model.priority_id == sv.Value ? " checked=\"checked\"" : "") />
                        @sv.Text
                    </label>
                }
            </td>

        </tr>
        <tr>
            <td>@Multi.secret_id<!--secret_Staus--></td>
            <td class="radio_form">
                @foreach (var sv in secrets)
                {
                    <label>
                        <input type="radio" name="secret_id" class="secret_id" value="@sv.Value" @(Model.secret_id == sv.Value ? " checked=\"checked\"" : "") />
                        @sv.Text
                    </label>
                }
            </td>
            <td rowspan="2">@Multi.remark</td>
            <td class="tdBottom" rowspan="2">
                <textarea id="note-input" class="half-textarea" name="note-input"></textarea>
            </td>


        </tr>
        <tr>
            <td>@Multi.call_back</td>
            <td>
                <select name="sue-staus" id="call_back">
                    <option value="F">ไม่ต้องการ</option>
                    <option value="T">ต้องการ</option>
                </select>
                <span class="star">*</span>
            </td>
        </tr>
    </table>
    <div class="boxBlank"></div>
    <div>
        <div class="BoxServiceActionPrev floatL" onclick="nextStep(3);">@Multi.BackPage</div>
        <div class="BoxServiceActionCancel floatR" onclick="resetform();">@Multi.Cancel</div>
        <div class="BoxServiceActionConfirm floatR" onclick="nextStep(5); getdataform();">@Multi.Confirm</div>
        <div class="clear"></div>
    </div>
</div>

<div class="dNone">
    <div id="inline_content">
        <div class="SaveSuccess">
            <div class="SaveSuccessTab1">@Multi.success</div>
            <div class="SaveSuccessTab2" id="result_save"></div>
            <div class="SaveSuccessTab3" onclick="$.colorbox.close();">@Multi.finish</div>
        </div>
    </div>
</div>

<script type="text/javascript" src="~/js/gg_map.js"></script>
<script type="text/javascript">

    var Lat_val = "13.751426";
    var Lng_val = "100.492582";

    var case_type = $("#block_case_type").val();

    $("#block_case_type").change(function () {
        var url = "@Url.Content("~/Complaint/LovCaseTypeOrgOwne")?case_type=" + $(this).val();
        $.getJSON(url)
            .done(function (json) {
                $('#district_id').html('');
                $.each(json, function (i, data) {
                    $('#district_id').append(
                        '<option value="' + data.Id + '">' + data.Name + '</option>'
                    );
                }
                )
            })
            .fail(function (jqxhr, textStatus, error) {
                //var err = textStatus + ", " + error;
                console.log("Request Failed: " + err);
            });
    });

    function addTextLocation2(locationToRedirect, newHref) {

        $('#district_achor').attr('href', newHref);

        $('#locationToRedirect').html(locationToRedirect);

        searchPlace();
    }
    //function selectOrgOwne() {
    //    var send_type_id = $('#block_case_type input[type=hidden]').val();
    //    alert(send_type_id);
    //    $.ajax({
    //        type: 'get',
    //        dataType: 'json',
    //        cache: false,
    //        url: '/Complaint/LovCaseTypeOrgOwne',
    //        data: { id: send_type_id},
    //        success: function (response, textStatus, jqXHR) {

    //        },
    //        error: function (jqXHR, textStatus, errorThrown) {
    //            alert('Error - ' + errorThrown);
    //        }
    //    });
    //}
    $.fn.serializeObject = function () {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function () {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };

   var result_id = "";
    function getdataform() {

        //ข้อมูลการติดต่อ
        var date_opened = $("#date_opened").val(); //วันที่ติดต่อ date_opened
        var hour = $("#hour").val();
        var minute = $("#minute").val();
        var objective_id1 = $('#block_objective input[type=hidden]').val(); //$("#block_chanel").val(); //วัตถุประสงค์การแจ้งเรื่อง objective_id
        var channel_incoming_id = $('#block_chanel input[type=hidden]').val(); //ช่องทางการรับเรื่อง channel_incoming_id
        var date_open = date_opened + "" + hour +"" +minute;


        //ผู้ติดต่อnextpage3
        var cont_contact_detail = $("#cont_contact_detail").val();
        var cont_is_secret = $("#cont_is_secret").val();
        var cont_country_id = $("#cont_country_id").val();
        var cont_type = $("#cont_type").val();
        var cont_gender_id = $("#cont_gender_id").val();
        var cont_title = $("#cont_title").val();
        var cont_firstname = $("#cont_firstname").val();
        var cont_lastname = $("#cont_lastname").val();
        var cont_citizen_id = $("#cont_citizen_id").val();
        var cont_address = $("#cont_address").val();
        var cont_is_defective = $("#cont_is_defective").val();
        var cont_postcode = $("#cont_postcode").val();
        var cont_remark = $("#cont_remark").val();
        var cont_number = $("#cont_number").val();
        var cont_birthday = $("#cont_birthday").val();

        var cont_subdistrict_id = $("#cont_subdistrict_id").val();
        var cont_district_id = $("#cont_district_id").val();
        var cont_province_id = $("#cont_province_id").val();
        var is_secret = $("#is_secret").val();
        var cont_is_victim = $('#cont_is_victim').is(':checked');


        //ข้อมูลผู้เดือดร้อน
        var cust_is_public = $("#cust_is_public").val();
        var cust_type = $("#cust_type").val();
        var cust_country_id = $("#cust_country_id").val();
        var cust_gender_id = $("#cust_gender_id").val();
        var cust_title = $("#cust_title").val();
        var cust_firstname = $("#cust_firstname").val();
        var cust_lastname = $("#cust_lastname").val();
        var cust_citizen_id = $("#cust_citizen_id").val();
        var cust_address = $("#cust_address").val();
        var cust_is_defective = $("#cust_is_defective").val();
        var cust_postcode = $("#cust_postcode").val();
        var cust_number = $("#cust_number").val();
        var cust_remark = $("#cust_remark").val();
        var cust_birthday = $("#cust_birthday").val();
        var cust_contact_detail = $("#cust_contact_detail").val();
        var cust_subdistrict_id = $("#cust_subdistrict_id").val();
        var cust_district_id = $("#cust_district_id").val();
        var cust_province_id = $("#cust_province_id").val();

        //เรื่องร้องทุกข์
        var objective_id = $('input[name="obj"]').val();//$("#block_obj").val();  //วัตถุประสงค์ของการแจ้งเรื่อง
        var type_id = $('#block_case_type input[type=hidden]').val();  //ประเภทเรื่อง
        var terminal_type_id = $('#terminal_type_id input[type=hidden]').val(); //ประเภทเรื่องของหน่วยงาน
        var org_id = $('input[name^="organizatoin"]').val(); //หน่วยงานที่เกี่ยวข้อง
        var used_inform_with = $("#used_inform_with").val();//หน่วยงานที่เคยติดต่อเรื่องนี้
        var defendent = $("#defendent").val(); //ผู้ถูกร้อง
        var date_occurrenced_from = $("#date_occurrenced_from").val(); //วันที่เกิดเหตุ
        var case_area = $("#case_area").val(); //พื้นที่เกิดเหตุ
        var date_occurrenced_to = $("#date_occurrenced_to").val(); //ถึงวันที่
        var time_occurrenced = $("#time_occurrenced").val(); //ช่วงเวลาที่เกิดเหตุ
        var is_in_court = $("#is_in_court").val(); //อยู่ระหว่างฟ้องร้อง
        var priority_id = $(".priority_id").val();
        var severity_id = $(".severity_id").val();
        var secret_id = $(".secret_id").val();
        var call_back = $("#call_back").val(); //ต้องการให้ติดต่อกลับ
        var status_id = "1";//$('input[name="status"]').val();  //สถานะเรื่อง
        var summary = $("#summary").val(); //สรุปสาระสำคัญ
        var detail = $("#detail").val(); //รายละเอียดของเรื่อง
        var postcode = $("#postcode").val(); //รหัสไปรษณีย์
        var lat_value = $("#lat_value").val(); //ละติจูด
        var lon_value = $("#lon_value").val(); //ละติจูด
        var remark = $("#remark").val();//หมายเหตุ
        var country_id = $("#country_id").val();
        var province_id = $("#province_id").val();
        var subdistrict_id = $("#subdistrict_id").val();
        var district_id = $("#district_id").val();
        // เคสนี้ เนื่องจากใช้ javascript ในการส่งหน้าฟอร์ม จึงต้องสร้าง array เอง
        var file_name = Array();
        $('input[name^="file_name"]').each(function (i) {
            file_name.push($(this).val());
        });
        var file_content = Array();
        $('input[name^="file_content"]').each(function (i) {
            file_content.push($(this).val());
        });
        var file_description = Array();
        $('input[name^="file_description"]').each(function (i) {
            file_description.push($(this).val());
        });
        var doc_type_id = Array();
        $('input[name^="doc_type_id"]').each(function (i) {
            doc_type_id.push($(this).val());
        });
        var doc_no = Array();
        $('input[name^="doc_no"]').each(function (i) {
            doc_no.push($(this).val());
        });
        var doc_date = Array();
        $('input[name^="doc_date"]').each(function (i) {
            doc_date.push($(this).val());
        });
        var doc_ref_no = Array();
        $('input[name^="doc_ref_no"]').each(function (i) {
            doc_ref_no.push($(this).val());
        });
        var doc_ref_date = Array();
        $('input[name^="doc_ref_date"]').each(function (i) {
            doc_ref_date.push($(this).val());
        });
        var doc_type = Array();
        $('input[name^="doc_type"]').each(function (i) {
            doc_type.push($(this).val());
        });

        var org_master_id = $('#block_organizatoin input[type="radio"]:checked').val();
        var date_closed = "";
        var channel_outgoing_id = "";


        if (objective_id == null) {
            alert("กรุณาระบุวัตถุประสงค์การแจ้งเรื่อง");
            nextStep(4);
        }
        else if (type_id == null) {
            alert("กรุณาระบุประเภทเรื่อง");
            nextStep(4);
        } else if (detail == null) {
            alert("กรุณาระบุุรายละเอียด");
            nextStep(4);
        } else if (status_id == null) {
            alert("กรุณาระบุสถานะการดำเนินการ");
            nextStep(4);
        }
        else if (call_back == null) {
            alert("กรุณาระบุสถานะการติดต่อกลับ");
            nextStep(4);
        }
        else if (severity_id == null) {
            alert("กรุณาระบุชั้นความเร่งด่วน");
            nextStep(4);
        }
        else if (priority_id == null) {
            alert("กรุณาระบุชั้นความสำคัญ");
            nextStep(4);
        }
        else if (secret_id == null) {
            alert("กรุณาระบุชั้นความลับ");
            nextStep(4);
        }
        else {


            $.ajax({
                type: 'post',
                dataType: 'json',
                cache: false,
                url: 'Complaint/InformCase',
                data: /*$('#form_inform_case_complaint').serializeObject()/**/ {
                    objective_id: objective_id, type_id: type_id, terminal_type_id: terminal_type_id, status_id: status_id,
                    date_opened: date_opened, date_closed: date_closed, channel_incoming_id: channel_incoming_id, call_back: call_back,
                    channel_outgoing_id: channel_outgoing_id, summary: summary, detail: detail, defendent: defendent, used_inform_with: used_inform_with,
                    date_occurrenced_from: date_occurrenced_from, date_occurrenced_to: date_occurrenced_to
                    , time_occurrenced: time_occurrenced, country_id: country_id, case_area: case_area, subdistrict_id: subdistrict_id, district_id: district_id, province_id: province_id,
                    postcode: postcode, latitude: lat_value, longitude: lon_value, case_value: 0, is_in_court: is_in_court, remark: remark,
                    is_secret: is_secret, priority_id: priority_id, severity_id: severity_id, secret_id: secret_id, org_master_id: org_master_id, org_id: org_id,
                    cont_is_secret: cont_is_secret, cont_type: cont_type, cont_gender_id: cont_gender_id, cont_title: cont_title, cont_firstname: cont_firstname,
                    cont_lastname: cont_lastname, cont_citizen_id: cont_citizen_id, cont_contact_detail: cont_contact_detail, cont_country_id: cont_country_id, cont_address: cont_address,
                    cont_subdistrict_id: cont_subdistrict_id, cont_district_id: cont_district_id, cont_province_id: cont_province_id, cont_postcode: cont_postcode, cont_birthday: cont_birthday,
                    cont_remark: cont_remark, cont_number: cont_number, cont_is_defective: cont_is_defective, cont_is_victim: cont_is_victim, cust_type: cust_type,
                    cust_gender_id: cust_gender_id, cust_title: cust_title, cust_firstname: cust_firstname, cust_lastname: cust_lastname, cust_citizen_id: cust_citizen_id, cust_contact_detail: cust_contact_detail,
                    cust_country_id: cust_country_id, cust_number: cust_number, cust_address: cust_address, cust_subdistrict_id: cust_subdistrict_id, cust_district_id: cust_district_id,
                    cust_province_id: cust_province_id, cust_postcode: cust_postcode, cust_birthday: cust_birthday, cust_remark: cust_remark, cust_is_defective: cust_is_defective,
                    cust_is_public: cust_is_public,
                    "file_name[]": file_name,
                    "file_content[]": file_content,
                    "file_description[]": file_description,
                    "doc_type_id[]": doc_type_id,
                    "doc_no[]": doc_no,
                    "doc_date[]": doc_date,
                    "doc_ref_no[]": doc_ref_no,
                    "doc_ref_date[]": doc_ref_date,
                    "doc_type[]": doc_type

                }
                ,
                success: function (response, textStatus, jqXHR) {

                   // savedataform2(response.result_text);
                    
                    result_id = response.result_text;
                    console.log(result_id);

                    if (response.successOrNot == true) {
                        parseDataToPage5ByJs(response.case_id);
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    nextStep(4);
                    //alert('Error - ' + errorThrown);
                }
            });
        }
}
   
    
    function savedataformData() {

        $('#result_save').html("รหัส : "+result_id);
        $.colorbox({
            inline: true,
            width: "50%",
            href: "#inline_content",
            fastIframe: false,
            onClosed: function () {

               // savedataform2(result_id);
                window.location.href = '/GroupList/ViewCase?id=' + result_id;
                
            }
        });
    }


//function savedataform2(text_message) {

//    $.colorbox({
//        inline: true,
//        width: "50%",
//        href: "#inline_content",
//        fastIframe: false,
//        onClosed: function () {
//            $("#comment").val('');
//        }
//    });
//}

function parseDataToPage5ByJs(case_id) {
    $('#page_5').attr('src', '@Url.Action("GetCaseById", "Complaint")?case_id=' + case_id);
    }
</script>
